
#include <gtest/gtest.h>

#include "ic/InitCondition.h"
#include "mesh/GeneratedMesh.h"
#include <vtkm/cont/DataSet.h>

TEST(IC, 3D)
{
    GeneratedMesh mesh(Id3{ 2,1,1}, { 0,0,0 }, { 1,1,1 });
    mesh.Build();

    const auto &cellSet = mesh.GetCellSet();
    auto& coords = mesh.GetCoordinate();
    auto p = coords.GetDataAsMultiplexer();
    ArrayHandle<FloatDefault> var;
    var.Allocate(mesh.GetNumberOfCells());
    

    vtkm::cont::DataSet data_set;
    data_set.AddCoordinateSystem(coords);
    data_set.SetCellSet(cellSet);
    data_set.AddCellField("p", var);

   // SinIC ic{};
   // InitialCondition::Execute(SinIC{}, cellSet, coords.GetDataAsMultiplexer(), data_set.GetCellField("p"));

    vtkm::io::VTKDataSetWriter write("cell_set.vtk");
    write.WriteDataSet(data_set);
}

TEST(IC, BoundarySet)
{
    GeneratedMesh mesh(Id3{ 2,2,0 }, { 0,0,0 }, { 1,1,1 });
    mesh.Build();
    mesh.WriteCellSet("mesh.vtk", mesh.GetCellSet());

    auto& coords = mesh.GetCoordinate();


    vtkm::cont::DataSet data_set;
    data_set.AddCoordinateSystem(coords);
    data_set.SetCellSet(mesh.GetBoundarySet());
    data_set.AddCellField("p", ArrayHandle<FloatDefault>{});

    //SinIC ic{};
    //InitialCondition::Execute(SinIC{}, mesh.GetBoundarySet(), coords.GetDataAsMultiplexer(), data_set.GetCellField("p"));

    vtkm::io::VTKDataSetWriter write("boundary_set.vtk");
    write.WriteDataSet(data_set);
}


TEST(IC, FaceSet)
{
    GeneratedMesh mesh(Id3{ 10,10,10 }, { 0,0,0 }, { 1,1,1 });
    mesh.Build();

    vtkm::cont::DataSet data_set;
    data_set.AddCoordinateSystem(mesh.GetCoordinate());
    data_set.SetCellSet(mesh.GetFaceSet());
    data_set.AddCellField("p", ArrayHandle<FloatDefault>{});

    //SinIC ic{};
    //InitialCondition::Execute(SinIC{}, mesh.GetFaceSet(), mesh.GetCoordinate().GetDataAsMultiplexer(), data_set.GetCellField("p"));

    vtkm::io::VTKDataSetWriter write("face_set.vtk");
    write.WriteDataSet(data_set);
}